
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;


public class DBConnection {
	private Connection conn;
	private Statement stm;
/*
	public DBConnection() throws SQLException, ClassNotFoundException {
		Class.forName("com.mysql.jdbc.Driver");
        this.conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/banco", "root", "");
		this.stm = this.conn.createStatement();
	}
    */
	
	public DBConnection() {
        try {

            //Registrando o driver do mysql
            Class.forName("com.mysql.jdbc.Driver");

            //Criando a conex�o
            this.conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/onibus", "root", "");

            //Criando o statment
            this.stm = conn.createStatement();

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
	
	public static DBConnection getDB(){
		return new DBConnection();
	}
	
    public ResultSet query(String sql) {
        ResultSet rs = null;

        try {
            rs = stm.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return rs;
    }
	
    public void update(String sql) {
        try {
           stm.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
	
}	
	